<html>
<head><title>CS143 Project 1B Demo</title></head>
<body>
<p> TA: Please do not "TEST" your (especially, complicated) quries in this demo website. The loading of quries might kill the server. 
Also, the machine running this website a has VERY different setting from your virutal machine, for example, the memory size, so testing your quries in this page is meaningless. 
Since we grade your projects in a virtual machine. Please test your queries (especially queries with sub-queries) at your own machine. </p>
Type an SQL query in the following box:
<p>
<form  method="GET">
<textarea name="query" cols="60" rows="8"></textarea>
<input type="submit" value="Submit" />
</form>
</p>
<p><small>Note: tables and fields are case sensitive. Run "show tables" to see the list of
available tables.</small>
</p>
<?php               
$db_connection = mysql_connect("localhost", "cs143", "");                //line 21
if(!$db_connection) {
    //$errmsg = mysql_error($db_connection);
   // print "Connection failed: $errmsg <br />;
    //exit(1);
die("Could not connect: " . mysql_error());
}

mysql_select_db("CS143", $db_connection);
$query = $_GET["query"];

$rs = mysql_query($query, $db_connection);
echo  $query;
if (!$rs) {
   echo 'Could not run query: ' . mysql_error();
   exit;
   }
 
 
echo "<table>\n<tr>";
 for ($i=0; $i < mysql_num_fields($rs); $i++) //Table Header
 { print "<th>".mysql_field_name($rs, $i)."</th>"; } 
 echo "</tr>\n";
 while ($row = mysql_fetch_row($rs)) { //Table body
 echo "<tr>";   
     for ($f=0; $f < mysql_num_fields($rs); $f++) { 
     echo "<td>$row[$f]</td>"; }
 echo "</tr>\n";}


 echo "</table><p>";
 



mysql_close($db_connection);

?>
</body>
</html>
